package com.ruoyi.biz.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.biz.domain.BizFee;
import com.ruoyi.biz.service.IBizFeeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 费用Controller
 * 
 * @author ruoyi
 * @date 2021-11-15
 */
@Controller
@RequestMapping("/biz/fee")
public class BizFeeController extends BaseController
{
    private String prefix = "biz/fee";

    @Autowired
    private IBizFeeService bizFeeService;

    @RequiresPermissions("biz:fee:view")
    @GetMapping()
    public String fee()
    {
        return prefix + "/fee";
    }

    /**
     * 查询费用列表
     */
    @RequiresPermissions("biz:fee:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizFee bizFee)
    {
        startPage();
        List<BizFee> list = bizFeeService.selectBizFeeList(bizFee);
        return getDataTable(list);
    }

    /**
     * 导出费用列表
     */
    @RequiresPermissions("biz:fee:export")
    @Log(title = "费用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizFee bizFee)
    {
        List<BizFee> list = bizFeeService.selectBizFeeList(bizFee);
        ExcelUtil<BizFee> util = new ExcelUtil<BizFee>(BizFee.class);
        return util.exportExcel(list, "费用数据");
    }

    /**
     * 新增费用
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存费用
     */
    @RequiresPermissions("biz:fee:add")
    @Log(title = "费用", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizFee bizFee)
    {
        return toAjax(bizFeeService.insertBizFee(bizFee));
    }

    /**
     * 修改费用
     */
    @GetMapping("/edit/{feeId}")
    public String edit(@PathVariable("feeId") Long feeId, ModelMap mmap)
    {
        BizFee bizFee = bizFeeService.selectBizFeeByFeeId(feeId);
        mmap.put("bizFee", bizFee);
        return prefix + "/edit";
    }

    /**
     * 修改保存费用
     */
    @RequiresPermissions("biz:fee:edit")
    @Log(title = "费用", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizFee bizFee)
    {
        return toAjax(bizFeeService.updateBizFee(bizFee));
    }

    /**
     * 删除费用
     */
    @RequiresPermissions("biz:fee:remove")
    @Log(title = "费用", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bizFeeService.deleteBizFeeByFeeIds(ids));
    }
}
